package com.mijie.fentsi;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.chenlb.mmseg4j.CharNode;
import com.chenlb.mmseg4j.Dictionary;
import com.chenlb.mmseg4j.CharNode.KeyTree;
import com.chenlb.mmseg4j.example.Complex;


public class MMsegFentsicyi extends Complex {

	 
/**
 * 4 lock
 */
	private static Object obj4lock=new Object();;

	/**
	 * 
	 * @param words
	 */
	public MMsegFentsicyi(List<String> words) {
	 
		dic = Dictionary.getInstance();
		
		 // 	dic = Dictionary.getInstance("");
//				dic=Dictionary4ati.getInstance("");
				
				
			
				
				
				//delete default words
				Map<Character, CharNode> dict=dic.getDict();		
				Set set=dict.keySet();
				Iterator<Character> it = set.iterator();  
				while (it.hasNext()) {  
					Character key = it.next();  
				//  String val=String.valueOf( dict.get(key));
				  CharNode cn=dict.get(key);
				  cn.ktWordTails=new   KeyTree();		  
				}  
				
				
				
				
				List<String> li=words;
				//li.add("上学好");
				//li.add("卖衣裳");
//				if(fentsiController.words_include_renvaEventKw!=null)
//					li=fentsiController.words_include_renvaEventKw;
				
				for(String word:li)
				{
					if(word.trim().length()==0 || word.length()<2)
						continue;
					String line=word;
					
					CharNode cn = dict.get(line.charAt(0));
					if(cn == null) {
						cn = new CharNode();
						dict.put(line.charAt(0), cn);
					}else
						cn.addWordTail(dic.tail(line));
					
				}
				
	}

	/**
	 * nbt multi thread
	 */
	/**
	 * 
	 */
	public  synchronized  List<String>	fentsi(String str)
	{
		synchronized(obj4lock)
		{
			Complex c=new Complex(5);
			c.dic=this.dic;
		List<String>  arr=	c.fentsi(str);
		    return arr;
		}
		 
	}
}
